#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>


//C文件接口
//int main()
//{
    //FILE* fp = fopen("dream","w+");
    //if(fp == NULL)
    //    return 1;
    //const char* str = "linux so easy!";
    //int len = strlen(str);
    //fwrite(str,len,1,fp);
    //
    //fseek(fp,0,SEEK_SET);
    //
    //char out[20];
    //fread(out,len,1,fp);
    //out[len] = '\0';
    //
    //printf("%s\n",out);
    //
    //fclose(fp);
    //return 0;
    
//}
//
//


//系统接口
int main()
{

    const char* s = "i like linux!!!\n";
    int fd = open("dream",O_WRONLY | O_CREAT | O_TRUNC,0777);
    
    write(fd,s,strlen(s));
    close(fd);
    fd = open("dream",O_RDONLY);
    char buffer[1024];
    ssize_t size = read(fd,buffer,1024);
    buffer[size] = '\0';

    write(stdout->_fileno,buffer,strlen(buffer));
    close(fd);

    return 0;
}


